import pinia from "@/stores";
import { useUserInfoStore } from "@/stores/userInfo";
import type { App } from "vue";

export default function (app: App) {
  const userInfoStore = useUserInfoStore(pinia)

  app.directive('has', {
    /* 
    组件挂载时执行
    el: 指令所有在标签, 也就是button
    binding: 包含指令相关数据的对象
        value: 指令属性值 也就按钮对应的权限值
    */
    mounted (el, binding) {
      // 如果value不在用户的按钮权限列表buttons中, 将当前el移除
      const buttons = userInfoStore.buttons
      if (!buttons.includes(binding.value)) {
        el.parentNode.removeChild(el)
      }
    }
  })
}